import Vue from 'vue'
import VueI18n from 'vue-i18n'
import zhCNLocale from './i18n_zh-CN'
import enUSLocale from './i18n_en-US'
import jaJPLocale from './i18n_ja-JP'
import elementLangEn from 'element-ui/lib/locale/lang/en'
import elementLangZhCN from 'element-ui/lib/locale/lang/zh-CN'
import elementLangJa from 'element-ui/lib/locale/lang/ja'
import ElementLocale from 'element-ui/lib/locale'
Vue.use(VueI18n)

const messages = {
  'zh-CN': Object.assign(zhCNLocale, elementLangZhCN),
  'en-US': Object.assign(enUSLocale, elementLangEn),
  'ja-JP': Object.assign(jaJPLocale, elementLangJa)
}
var lang = localStorage.getItem('locale')
if (lang === undefined || lang === null) {
  lang = 'zh-CN'
}
const dateTimeFormats = {
  'zh-CN': { yearMonth: { year: 'numeric', month: 'short' } },
  'ja-JP': { yearMonth: { year: 'numeric', month: 'short' } },
  'en-US': { yearMonth: { year: 'numeric', month: 'short' } }
}
const i18n = new VueI18n({
  dateTimeFormats: dateTimeFormats,
  locale: lang,
  messages
})
ElementLocale.i18n((key, value) => i18n.t(key, value))
export default i18n
